package com.think.teaching.mapper;

import com.think.teaching.model.CourseComment;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * <p>
 * 课程评论 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface CourseCommentMapper extends BaseMapper<CourseComment> {

	@Select("SELECT course_comment.id,content,user_id,u.nickname,reply_to,course_comment.created_time,u.avatar_url  FROM course_comment LEFT JOIN user u ON course_comment.user_id = u.id WHERE reply_to=-1 AND course_id=#{id}  ORDER BY course_comment.created_time DESC")
	@Results(id = "replies", value = { 
			@Result(column = "id", property = "id"),
			@Result(column = "content", property = "content"), 
			@Result(column = "user_id", property = "userId"),
			@Result(column = "nick_name", property = "nickName"),
			@Result(column = "id", property = "replies", many = @Many(select = "com.think.teaching.mapper.CourseCommentMapper.getCommentByReplyId")) })
	public IPage<Map<String, Object>> ListComment(IPage<Map<String, Object>> page, @Param("id")Integer id);

	@Select("SELECT course_comment.id,content,user_id,u.nickname,reply_to,course_comment.created_time,u.avatar_url  FROM course_comment LEFT JOIN user u ON course_comment.user_id = u.id WHERE reply_to=#{reply}  ORDER BY course_comment.created_time DESC")
	@ResultMap("replies")
	public List<Map<String, Object>> getCommentByReplyId(@Param("reply")Integer reply);
}
